
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

typedef SingleCallback<int> = void Function(int obj);

class ValSwitchButtonMenu extends StatefulWidget {

  final String? onString;
  final String? offString;
  final bool pressed;
  final SingleCallback? onTap;
  final double fontSize;
  final FontWeight fontWeight;

  ValSwitchButtonMenu({
    Key? key,
    required this.onString,
    required this.offString,
    required this.pressed,
    this.fontSize = 20.0,
    this.fontWeight = FontWeight.w600,
    required this.onTap
  });

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return ValSwitchButtonMenuState();
  }

}

class ValSwitchButtonMenuState extends State<ValSwitchButtonMenu> {

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return _switchButton();
  }

  Widget _switchButton() {
    BoxDecoration BoxDecoration_left1 = BoxDecoration(
      gradient: const LinearGradient(
        begin: Alignment.centerLeft,
        end: Alignment.centerRight,
        colors: [
          Color(0xFFE8A229),
          Color(0xFFF9C03D),
          Color(0xFFFCCC41),
        ],
      ),
      borderRadius: BorderRadius.circular(18)
    );
    BoxDecoration BoxDecoration_left2 = BoxDecoration(borderRadius: BorderRadius.circular(18));
    BoxDecoration BoxDecoration_right1 = BoxDecoration(borderRadius: BorderRadius.circular(18));
    BoxDecoration BoxDecoration_right2 = BoxDecoration(
      gradient: const LinearGradient(
        begin: Alignment.centerLeft,
        end: Alignment.centerRight,
        colors: [
          Color(0xFFE8A229),
          Color(0xFFF9C03D),
          Color(0xFFFCCC41),
        ],
      ),
      borderRadius: BorderRadius.circular(18)
    );
    TextStyle textStyle = TextStyle(fontSize: widget.fontSize, color: Colors.white, fontWeight: widget.fontWeight);
    TextStyle textStyle1 = TextStyle(fontSize: widget.fontSize, color: const Color(0xFF333333), fontWeight: widget.fontWeight);

    return Container(
      alignment: Alignment.center,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(20),
        border: Border.all(
          width: 1, style: BorderStyle.solid, color: const Color(0xFFE8A229))
      ),
      child: Row(
        children: <Widget>[
          Expanded(
            child: GestureDetector(
              child: Container(
                height: double.infinity,
                alignment: Alignment.center,
                decoration: widget.pressed ? BoxDecoration_left1 : BoxDecoration_left2,
                child: Text(widget.onString ?? "", style: widget.pressed ? textStyle1 : textStyle, ),
              ),
              onTap: () {
                if (widget.onTap != null){
                  widget.onTap!(0);
                }
              }
            ),
          ),
          Expanded(
            child: GestureDetector(
              child: Container(
                height: double.infinity,
                alignment: Alignment.center,
                decoration: widget.pressed ? BoxDecoration_right1 : BoxDecoration_right2,
                child: Text(widget.offString ?? "", style: widget.pressed ? textStyle : textStyle1),
              ),
              onTap: () {
                if (widget.onTap != null){
                  widget.onTap!(1);
                }
              }
            ),
          ),
        ],
      ),
    );
  }

}

